package com.dynabook.ems.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dynabook.ems.annotation.LoginRequired;
import com.dynabook.ems.common.BaseResponse;
import com.dynabook.ems.common.ResultUtils;
import com.dynabook.ems.model.dto.ProductListRequest;
import com.dynabook.ems.model.vo.ProductListVO;
import com.dynabook.ems.service.EmsMainEngineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 成品列表 控制器
 */
@Api(tags = {"改造品入库"})
@RestController
@RequestMapping("/product")
@Slf4j
public class ProductController {
    
    @Resource
    private EmsMainEngineService emsMainEngineService;
    
    /**
     * 获取成品列表
     */
    @PostMapping("/list")
    @ApiOperation(value = "获取成品入库列表", notes = "分页查询成品列表，支持搜索工单号、成品型号、机型名称")
    @LoginRequired
    public BaseResponse<Page<ProductListVO>> getProductList(@RequestBody @Valid ProductListRequest productListRequest,
                                                           HttpServletRequest request) {
        log.info("获取成品列表，请求参数：{}", productListRequest);
        Page<ProductListVO> productPage = emsMainEngineService.getProductList(productListRequest);
        return ResultUtils.success(productPage);
    }
    
    /**
     * 获取旧品入库列表
     */
    @PostMapping("/old-list")
    @ApiOperation(value = "获取旧品入库列表", notes = "分页查询旧品列表，支持搜索工单号、成品型号、机型名称")
    @LoginRequired
    public BaseResponse<Page<ProductListVO>> getOldProductList(@RequestBody @Valid ProductListRequest productListRequest,
                                                              HttpServletRequest request) {
        log.info("获取旧品入库列表，请求参数：{}", productListRequest);
        Page<ProductListVO> productPage = emsMainEngineService.getOldProductList(productListRequest);
        return ResultUtils.success(productPage);
    }
} 